import 'package:car_map/mode/device_model.dart';
import 'package:car_map/widget/load_image.dart';
import 'package:car_map/widget/widget_search_textfield.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LabelPage extends StatefulWidget{
  @override
  _labelState createState() =>_labelState();

}

class _labelState extends State<LabelPage>{

  List<DeviceModel> modelList;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    deviceList();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.only(left: 10.0,right: 10.0,top: 10.0),
      child: ListView(
        children: <Widget>[
          WidgetSearchTextField(),
          getWidgetDeviceList(),
        ],
      ),
    );
  }

  //设备列表数据
  List<DeviceModel> deviceList(){
    modelList=new List();
    modelList.add(new DeviceModel(titleValue: '都香高速A4合同段车辆',allDevice: 9,onlineDevice: 7));
    modelList.add(new DeviceModel(titleValue: '海秀快速路二期项目车辆',allDevice: 10,onlineDevice:25));
    modelList.add(new DeviceModel(titleValue: '莆炎YA6项目车辆',allDevice: 0,onlineDevice: 1));
    modelList.add(new DeviceModel(titleValue: '泉厦漳联盟路A3标车辆',allDevice:1,onlineDevice: 0));
    modelList.add(new DeviceModel(titleValue: '万州环线二分部车辆',allDevice: 9,onlineDevice: 8));
    modelList.add(new DeviceModel(titleValue: '漳武高速公路南A1合同段车辆',allDevice: 0,onlineDevice: 1));
  }

  Widget getWidgetDeviceList(){
    return ListView.builder(itemBuilder: (context,index){
      return itemDevice(modelList[index]);
    },itemCount: modelList.length,shrinkWrap: true,physics: new NeverScrollableScrollPhysics(),);
  }

  //设备清单item
  Widget itemDevice(DeviceModel deviceModel){
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: Colors.black12,
                  width: 0.5
              )
          )
      ),
      child: ListTile(
        onTap: (){

        },
        title: Text(deviceModel.titleValue),
        leading: LoadAssetImage(
          'grouping/ic_grading',
          width: ScreenUtil().setWidth(30.0),
          height: ScreenUtil().setHeight(30.0),
        ),
        trailing:Icon(Icons.navigate_next),
        subtitle: Text('(${deviceModel.onlineDevice}/${deviceModel.allDevice})'),
      ),
    );
  }

}